<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta charset='utf-8' />
	<title>台账后台</title>
	<style>
		.cursers{cursor:pointer}
	</style>
</head>
<body style='background:#ddd;padding:0px;margin:0px;padding-left:10px'>
	<div style='border:0px solid;font:normal normal 12px/30px normal'>
		<div style='float:right;padding-right:10px'>
			<span class='cursers' onclick='location.href="password.html"'>当前用户：<span style='color:#229' id='account'>admin</span>　</span>
			<span style='color:blue' class='cursers' onclick='exits()'>退出</span>　
		</div>
		<div style='clear:both'></div>
	</div>

	<div>
		<h1 style='text-align:center'>后台管理</h1>		
	</div>

	<div style='border:0px solid;'>
		<div style='margin-left:25px;float:left'>
			<label><input type="radio" name='stype' value='all'/>全部</label>
			<label><input type="radio" name='stype' value='1' />待审</label>
			<label><input type="radio" name='stype' value='2' />正常</label>
			<label><input type="radio" name='stype' value='3' />封禁</label>
		</div>

		<div style='float:right;padding-right:10px'>
			<select id="searchSel">
				<option value="number">按工号</option>
				<option value="name">按姓名</option>
			</select>
			<input type="text" placeholder='输入关键字' id='searchInp' />
			<button id='searchBtn'>搜索</button>
		</div>
		<div style='clear:both'></div>
	</div>

	<table style='border:0px solid;width:100%;margin:30px 0'>
		<tr>
			<th>工号</th>
			<th>姓名</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
		<tbody id='userList' style='font-size:12px'>
			
		</tbody>
	</table>
	

	<div id='fpage' style='text-align:center;padding:5px'></div>

</body>
</html>
<script src='../public/jquery1.1.js'></script>
<script src='../public/fun.js'></script>
<script>
_checkExit(1);	//检测账号异常强制退出

if(!sessionStorage.ledgerAdminMainPnow){
	sessionStorage.ledgerAdminMainPnow = 1;
}
if(!sessionStorage.ledgerAdminMainMax){
	sessionStorage.ledgerAdminMainMax = parseInt(sessionStorage.ledgerAdminMainPnow) + 1;
}
if(!sessionStorage.ledgerAdminMainStype){
	sessionStorage.ledgerAdminMainStype = 'all';
}else{
	$('input[type=radio]').each(function(i,o){
		if($(o).val() == sessionStorage.ledgerAdminMainStype){
			o.checked = true;
		}
	});
}


if(sessionStorage.ledgerAdminMainSearchInp){
	$('#searchInp').val(sessionStorage.ledgerAdminMainSearchInp);
}else{
	sessionStorage.ledgerAdminMainSearchInp = '';
}

if(sessionStorage.ledgerAdminMainSearchSel){
	$('#searchSel').val(sessionStorage.ledgerAdminMainSearchSel);
}else{
	sessionStorage.ledgerAdminMainSearchSel = $('#searchSel').find('option:selected').val();
}

//获取用户列表
function _getUserList(){
	var data = {
		'type':'_getUserList',
		'pnow':sessionStorage.ledgerAdminMainPnow,
		'stype':sessionStorage.ledgerAdminMainStype,
		'searchSel':sessionStorage.ledgerAdminMainSearchSel,
		'searchInp':sessionStorage.ledgerAdminMainSearchInp
	}
	AjaxAfter(data,function(res){
		var tmp = _checkJsonFormat(res,1);
		_parseData(tmp.data);
	});
}

function _parseData(data){
	if(typeof(data) != 'object' || data.length < 1){
		sessionStorage.ledgerAdminMainPnow = parseInt(sessionStorage.ledgerAdminMainPnow);
		sessionStorage.ledgerAdminMainMax = sessionStorage.ledgerAdminMainPnow;
	}
	var str = '';
	for(var i=0;i<data.length;i++){
		switch(data[i].stat){
			case '1':
				var stat = '<span style="color:blue">待审</span>';
				var btnStr = '通过';
				break;
			case '2':
				var stat = '正常';
				var btnStr = '封禁';
				break;
			case '3':
				var stat = '<span style="color:red">封禁</span>';
				var btnStr = '解封';
				break;
		}
		var tmp_id = 'uc_' + i;
		str += "<tr style='text-align:center'><td>" + data[i].account + "</td><td>" + data[i].name + "</td><td>"+ stat +"　<button onclick=_changeStat("+ data[i].id +")>"+ btnStr +"</button></td><td><button onclick=_resetPwd("+data[i].id+")>重置密码</button></td></tr>";
	}
	$('#userList').html(str);

	Fpage(parseInt(sessionStorage.ledgerAdminMainPnow),parseInt(sessionStorage.ledgerAdminMainMax),function(p){
		sessionStorage.ledgerAdminMainPnow = p;
		sessionStorage.ledgerAdminMainMax = parseInt(p) + 1;
		location.reload();
	},1,1,'#fpage');
}












//更改用户状态
function _changeStat(id){
	if(!confirm('确认操作？')){
		return;
	}
	if(!id){
		return;
	}
	var data = {
		type:'_changeStat',
		id:id
	}
	AjaxAfter(data,function(res){
		var tmp = _checkJsonFormat(res,1);
		if(tmp.stat == 'ok'){
			A('操作成功！');
			location.reload();
		}else{
			A('操作失败！');
		}
	});
}



//重置密码
function _resetPwd(id){
	if(!confirm('确认操作？')){
		return;
	}
	if(!id){
		return;
	}
	var data = {
		type:'_resetPwd',
		id:id
	}
	AjaxAfter(data,function(res){
		var tmp = _checkJsonFormat(res,1);
		if(tmp.stat == 'ok'){
			A('密码重置为123！');
		}else{
			A('密码重置为123！');
		}
	});
}


$(function(){


	$('#account').text(sessionStorage.ledgerAdminAccount);	//显示当前用户名

	_getUserList();	//获取用户列表


	$('input[type=radio]').change(function(){
		sessionStorage.ledgerAdminMainStype = $(this).val();
		sessionStorage.ledgerAdminMainPnow = 1;
		sessionStorage.ledgerAdminMainMax = 2;
		location.reload();
	});


	$('#searchBtn').click(function(){
		sessionStorage.ledgerAdminMainPnow = 1;
		sessionStorage.ledgerAdminMainMax = 2;
		sessionStorage.ledgerAdminMainStype = 'all';
		var searchInp = m_trim($('#searchInp').val());
		if(searchInp == sessionStorage.ledgerAdminMainSearchInp){
			//return;
		}

		sessionStorage.ledgerAdminMainSearchInp = searchInp;
		location.reload();
	});

	$('#searchSel').change(function(){
		var searchSel = $(this).find('option:selected').val();
		sessionStorage.ledgerAdminMainSearchSel = searchSel;
	});
});	




//退出 
function exits(){
	AjaxAfter({type:'exit'},function(res){
		if(res == 'ok'){
			sessionStorage.clear();
			location.replace('login.html');
		}
	});
}
</script>

